package com.atuguigu.realtime.gmalllogger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/2/3 22:32
 */
@RestController
@Slf4j
public class LoggerController {

    @GetMapping("/applog")  // 提交路径
    public String doLog(@RequestParam("param") String logString) {
        // 1.日志落盘
        saveToDisk(logString);
        // 2. 数据写入到kafka
        sendToKafka(logString);

        return "ok";
    }

    @Autowired
    private KafkaTemplate<String, String> kafka;

    private void sendToKafka(String logString) {
        kafka.send("ods_log", logString);
    }

    private void saveToDisk(String logString) {
        log.info(logString);
    }

}
